package de.in.michael.unnamed.gfx;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Art
{
	public static Art i;

	public static void init()
	{
		i = new Art();
	}

	public Bitmap[][] sprites = loadAndCut("/sprites.png", 8, 8);
	public Bitmap[][] font = loadAndCut("/font.png", 6, 6);

	public Bitmap[][] loadAndCut(String name, int sw, int sh)
	{
		BufferedImage res;

		try
		{
			res = ImageIO.read(Art.class.getResource(name));
		}
		catch (IOException e)
		{
			throw new RuntimeException("Can't load: " + name);
		}

		int xSlices = res.getWidth() / sw;
		int ySlices = res.getHeight() / sh;

		Bitmap[][] result = new Bitmap[xSlices][ySlices];

		for (int x = 0; x < xSlices; x++)
		{
			for (int y = 0; y < ySlices; y++)
			{
				result[x][y] = new Bitmap(sw, sh);
				res.getRGB(x * sw, y * sh, sw, sh, result[x][y].pixels, 0, sw);
			}
		}
		return result;
	}
}
